package com.ssy.lingxi.platform.manage.controller.content;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.entity.content.MemberColumn;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonStatusRequest;
import com.ssy.lingxi.platform.manage.model.request.content.MemberColumnPageRequest;
import com.ssy.lingxi.platform.manage.model.request.content.MemberColumnRequest;
import com.ssy.lingxi.platform.manage.model.response.HotColumnResponse;
import com.ssy.lingxi.platform.manage.service.content.IMemberColumnService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @menu 内容能力-栏目管理
 * @author wyx
 * @version 2.0.0
 * @date 2021-09-28
 */
@RestController
@RequestMapping("/manage/member/column")
public class MemberColumnController extends BaseController {

    @Resource
    private IMemberColumnService memberColumnService;


    /**
     * 栏目列表
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<MemberColumn>> page(MemberColumnPageRequest request) {
        return memberColumnService.page(request, getSysUser());
    }

    /**
     * 栏目详情
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping(value = "/get")
    public Wrapper<MemberColumn> get(@Validated CommonIdRequest request) {
        return memberColumnService.get(request);
    }

    /**
     * 新增栏目
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Validated({MemberColumnRequest.Add.class}) MemberColumnRequest request) {
        return memberColumnService.add(request, getSysUser());
    }

    /**
     * 修改栏目
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Validated({MemberColumnRequest.Update.class}) MemberColumnRequest request) {
        return memberColumnService.update(request, getSysUser());
    }

    /**
     * 停用/启用
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/updateStatus")
    public Wrapper<Void> updateStatus(@RequestBody @Validated({CommonStatusRequest.Enable.class}) CommonStatusRequest request) {
        return memberColumnService.updateStatus(request, getSysUser());
    }

    /**
     * 删除栏目
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Validated CommonIdRequest request) {
        return memberColumnService.delete(request, getSysUser());
    }

    /**
     * 所有栏目
     * @param type 栏目分类：1.市场行情；2.资讯
     * @return 查询结果
     */
    @GetMapping(value = "/all")
    public Wrapper<List<MemberColumn>> all(Integer type) {
        return memberColumnService.all(type, getSysUser());
    }

    /**
     * 所有（市场行情）
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/allByMarket")
    public Wrapper<List<MemberColumn>> allByMarket(Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberColumnService.allByMarket(user);
    }

    /**
     * 热门栏目
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/hot")
    public Wrapper<List<HotColumnResponse>> hot(Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberColumnService.hot(user);
    }
}
